package com.foronenet.upd;

import cn.hutool.core.util.HexUtil;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.util.Arrays;

public class UdpServerDemo {
    public static void main(String[] args) throws IOException {
        DatagramSocket socket = new DatagramSocket(8081);
        byte[] buffer = new byte[16];
        DatagramPacket packet = new DatagramPacket(buffer, buffer.length);

        while (true) {
            socket.receive(packet);
            System.out.println(packet.getAddress()
                    +":" + packet.getPort()
                    +"=>" + packet.getLength()
                    +"=>" + HexUtil.encodeHexStr(packet.getData()));
        }
    }
}
